<template>
  <div class="login-container">
    <h1 class="box__title">
      <img src="@/assets/imgs/logo.png" />
      <!-- <img src="/favicon.ico" /> -->
      {{ VITE_APP_TITLE }}
    </h1>
    <div class="form-box">
      <div class="form-box__title">登录您的账户</div>
      <div class="form-box__container">
        <ElInput
          v-model="loginForm.username"
          type="text"
          size="large"
          prefix-icon="icon-user"
          autocomplete="username"
          placeholder="用户名"
        />
        <ElInput
          v-model="loginForm.password"
          type="password"
          size="large"
          prefix-icon="icon-lock"
          autocomplete="current-password"
          placeholder="密码"
          style="margin-bottom: 5px"
        />
        <div class="forgotPassword">忘记密码</div>
      </div>

      <div class="form-box__footer">
        <el-button
          type="primary"
          size="large"
          :loading="loginLoading"
          @click="login"
          >登 录</el-button
        >
      </div>
    </div>
  </div>
  <footer>
    <div>
      <div class="footer-title">
        关于本网&nbsp;&nbsp;I&nbsp;&nbsp;网站声明&nbsp;&nbsp;I&nbsp;&nbsp;联系我们
      </div>
      <div class="footer-item">
        链接：
        渝快办&nbsp;&nbsp;I&nbsp;&nbsp;渝中快政&nbsp;&nbsp;I&nbsp;&nbsp;国家政府服务平台&nbsp;&nbsp;I&nbsp;&nbsp;国家政协&nbsp;&nbsp;I&nbsp;&nbsp;云阳县人民政府
      </div>
      <div class="footer-item">
        版权所有：重庆市人民政府网站&nbsp;京ICP备05070218号-3
      </div>
      <div class="footer-item">
        <img src="@/assets/imgs/f1.png" />
        京公网安备 11010202001001号
      </div>
    </div>
  </footer>
</template>

<script setup lang="ts">
import config from '@/config'
import { useLogin } from './hooks/useLogin'
import { useSSOLogin } from './hooks/useSSOLogin'
import { useYKBSSOLogin } from './hooks/useYKBSSOLogin'

defineOptions({
  name: config.routeLoginName
})

const VITE_APP_TITLE = import.meta.env.VITE_APP_TITLE

// 获取当前页面的 URL
const url = new URL(window.location.href)

const toFunHooks = () => {
  let auth_code = '',
    authCode = ''
  if (url.href.indexOf('authCode') > 0) {
    //愉快办
    let paramsStr = url.href.split('?')
    const params = new URLSearchParams(paramsStr[1])
    authCode = params.get('authCode')
  } else if (url.href.indexOf('auth_code') > 0) {
    //愉快政
    // 使用 URLSearchParams 提取查询参数
    const params = new URLSearchParams(url.search)
    auth_code = params.get('auth_code')
  }

  if (import.meta.env.MODE === 'prod') {
    if (authCode) {
      useYKBSSOLogin()
    } else if (auth_code) {
      useSSOLogin()
    }
  }
}
toFunHooks()

const { loginLoading, loginForm, login } = useLogin()
</script>

<style scoped lang="scss">
@use 'login';

/* 当屏幕宽度小于或等于768像素时，应用以下样式 */
@media (max-width: 420px) {
  .form-box {
    width: 360px !important;
    height: 440px !important;
    top: 50% !important;
  }

  .box__title {
    left: 30px !important;
  }

  footer {
    display: none;
  }
}
</style>
